package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.MeetingRoomStatusPageQueryDTO;
import com.sky.entity.MeetingRoom;
import com.sky.entity.MeetingRoomDetail;
import com.sky.mapper.MeetingRoomStatusMapper;
import com.sky.result.PageResult;
import com.sky.service.MeetingRoomStatusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class MeetingRoomStatusServiceImpl implements MeetingRoomStatusService {

    @Autowired
    private MeetingRoomStatusMapper meetingRoomStatusMapper;

    @Override
    // 分页查询会议室状态
    public PageResult pageQuery(MeetingRoomStatusPageQueryDTO meetingRoomStatusPageQueryDTO) {
        // 设置分页参数
        PageHelper.startPage(meetingRoomStatusPageQueryDTO.getPage(),meetingRoomStatusPageQueryDTO.getPageSize());   //设置分页查询参数

        // 调用mapper查询数据
        Page<MeetingRoomDetail> page = meetingRoomStatusMapper.pageQuery(meetingRoomStatusPageQueryDTO);

        Long total=page.getTotal(); // 满足条件的总记录数
        List<MeetingRoomDetail> meetingRoomList=page.getResult(); //满足条件的所有记录

        return new PageResult(total,meetingRoomList);
    }

    /**
     * 定时检查和修改会议室状态
     */
    @Override
    public void checkMeetingRoomStatus() {
        meetingRoomStatusMapper.checkMeetingRoomStatus();
    }
}
